package com.aidex.common.core.domain.entity;

import com.aidex.common.annotation.Excel;
import com.aidex.common.core.domain.BaseEntity;
import com.baomidou.mybatisplus.annotation.TableField;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.apache.commons.lang3.StringUtils;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.Size;

@Data
@EqualsAndHashCode(callSuper = true)
@Api(tags = "角色对象")
public class SysRole extends BaseEntity {

    @ApiModelProperty("角色名称")
    @Excel(name = "角色名称")
    @NotBlank(message = "角色名称不能为空")
    @Size(max = 30, message = "角色名称长度不能超过30个字符")
    private String roleName;

    @ApiModelProperty("角色权限")
    @Excel(name = "角色权限")
    @NotBlank(message = "权限字符不能为空")
    @Size(max = 100, message = "权限字符长度不能超过100个字符")
    private String roleKey;

    @ApiModelProperty("角色排序")
    @Excel(name = "角色排序")
    @NotBlank(message = "显示顺序不能为空")
    private String sort;

    @ApiModelProperty("数据范围（1：所有数据权限；2：自定义数据权限；3：本部门数据权限；4：本部门及以下数据权限；5：仅本人数据权限）")
    @Excel(name = "数据范围" , readConverterExp = "1=所有数据权限,2=自定义数据权限,3=本部门数据权限,4=本部门及以下数据权限,5=仅本人数据权限")
    private String dataScope;

    @ApiModelProperty("角色状态")
    @Excel(name = "角色状态" , readConverterExp = "0=正常,1=停用")
    private String status;

    @ApiModelProperty("菜单组")
    @TableField(exist = false)
    private String[] menuIds;

    @ApiModelProperty("部门组")
    @TableField(exist = false)
    private String[] deptIds;

    @ApiModelProperty("操作")
    @TableField(exist = false)
    private String option;

    @TableField(exist = false)
    private Boolean admin;

    public SysRole() {

    }

    public SysRole(String id) {
        setId(id);
    }

    public boolean isAdmin() {
        return isAdmin(this.getId());
    }

    public static boolean isAdmin(String id) {
        return StringUtils.isNotBlank(id) && "1".equals(id);
    }

}
